package com.Lemon.Zhkuhealth.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.Lemon.Zhkuhealth.common.pojo.entity.CheckItem;
import com.Lemon.Zhkuhealth.common.util.PageResult;
import com.Lemon.Zhkuhealh.api.service.ICheckItemService;
import com.Lemon.Zhkuhealth.provider.mapper.CheckItemMapper;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;

import java.util.List;

/**
 * Some description here.
 *
 * @author LanPingX.com
 * @version 1.0, 2023/08/21
 */
@DubboService
@RequiredArgsConstructor
public class CheckItemServiceImpl implements ICheckItemService {

    private final CheckItemMapper checkItemMapper;

    @Override
    public Integer save(CheckItem checkItem) {
        return checkItemMapper.insert(checkItem);
    }

    @Override
    public PageResult<CheckItem> page(Integer currentPage, Integer pageSize, String queryString) {
        // 0.构造查询条件语句
        LambdaQueryWrapper<CheckItem> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper
                .like(null != queryString, CheckItem::getCode, queryString)
                .or()
                .like(null != queryString, CheckItem::getName, queryString);
        // 1. 通过分页参数创建分页对象
        Page<CheckItem> checkItemPage = new Page<>(currentPage, pageSize);
        // 2. 执行分页查询
        checkItemMapper.selectPage(checkItemPage, lambdaQueryWrapper);
        // 3. 返回分页结果
        return new PageResult<>(checkItemPage.getTotal(), checkItemPage.getRecords());
    }

    @Override
    public CheckItem getById(Long id) {
        return checkItemMapper.selectById(id);
    }

    @Override
    public Boolean updateById(CheckItem checkItem) {
        return checkItemMapper.updateById(checkItem) > 0;
    }

    @Override
    public Boolean deleteById(Long id) {
        return checkItemMapper.deleteById(id) > 0;
    }

    @Override
    public List<CheckItem> list() {
        return checkItemMapper.selectList(null);
    }
}
